package com.hktf.uilib.widget;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.permissionx.guolindev.dialog.RationaleDialog;
import com.hktf.uilib.R;

import java.util.List;

public class RequestPermissionDialog extends RationaleDialog {


    private TextView tvTitle;
    private TextView tvMsg;
    private Button btnNo;
    private Button btnYes;
    private List<String> permissionList;
    private View root;


    public RequestPermissionDialog(@NonNull Context context, String title, String msg,List<String> permission) {
        super(context, R.style.MyAlertDialog);
//        root = View.inflate(context, R.layout.dialog_permission, null);
//        addContentView(root,new ActionBar.LayoutParams(
//                ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT));
        setContentView(R.layout.dialog_permission);
        initView();
        if (title != null) {
            tvTitle.setText(title);
        }
        if (msg != null) {
            tvMsg.setText(msg);
        }
        permissionList=permission;

//        Window window = getWindow();
//        WindowManager.LayoutParams lp = window.getAttributes();
//        lp.width = (int) DisplayUtil.dip2px(context, 500); // 设置宽度
//        //            lp.width =UIUtils.dip2px(300); // 设置宽度
//        LogMds.e("DialogUtil", "width=" + lp.width);
//        window.setAttributes(lp);
    }

    @NonNull
    @Override
    public View getPositiveButton() {
        return btnYes;
    }

    @Nullable
    @Override
    public View getNegativeButton() {
        return btnNo;
    }

    @NonNull
    @Override
    public List<String> getPermissionsToRequest() {
        return permissionList;
    }


    private void initView() {
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvMsg = (TextView) findViewById(R.id.tv_msg);
        btnNo = (Button) findViewById(R.id.btn_no);
        btnYes = (Button) findViewById(R.id.btn_yes);
//        tvTitle = (TextView) root.findViewById(R.id.tv_title);
//        tvMsg = (TextView) root.findViewById(R.id.tv_msg);
//        btnNo = (Button) root.findViewById(R.id.btn_no);
//        btnYes = (Button) root.findViewById(R.id.btn_yes);
    }
}
